{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "initial_id",
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    ""
   ]
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "举例1：从物理磁盘的yaml文件中读取prompt数据",
   "id": "69ad7b3cc31286a1"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-08-25T09:29:12.249416Z",
     "start_time": "2025-08-25T09:29:11.905916Z"
    }
   },
   "cell_type": "code",
   "source": [
    "from langchain_core.prompts import load_prompt\n",
    "import dotenv\n",
    "\n",
    "dotenv.load_dotenv()\n",
    "\n",
    "prompt = load_prompt(\"prompt.yaml\", encoding=\"utf-8\")\n",
    "# print(prompt)\n",
    "print(prompt.format(name=\"年轻人\", what=\"滑稽\"))"
   ],
   "id": "a18b60da92c052ea",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请给年轻人讲一个关于滑稽的故事\n"
     ]
    }
   ],
   "execution_count": 1
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "举例2：从物理磁盘的json文件中读取prompt数据",
   "id": "24455ae62db5559"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-08-25T09:30:08.955430Z",
     "start_time": "2025-08-25T09:30:08.924244Z"
    }
   },
   "cell_type": "code",
   "source": [
    "from langchain_core.prompts import load_prompt\n",
    "from dotenv import load_dotenv\n",
    "\n",
    "load_dotenv()\n",
    "\n",
    "prompt = load_prompt(\"prompt.json\",encoding=\"utf-8\")\n",
    "print(prompt.format(name=\"张三\",what=\"搞笑的\"))"
   ],
   "id": "8a828375ae07ca8a",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请张三讲一个搞笑的的故事。\n"
     ]
    }
   ],
   "execution_count": 2
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
